package com.qf.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.annotation.RequiresPermissionsDesc;
import com.qf.pojo.DtsAddress;
import com.qf.service.DtsAddressService;
import com.qf.util.ResponseUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Zwnan
 */
@RestController
@RequestMapping("/admin/address")
@CrossOrigin
public class AddressController {

    @Autowired
    private DtsAddressService dtsAddressService;

    // page=1&limit=20&sort=add_time&order=desc
    @RequiresPermissionsDesc(menu = {"系统管理","地址"},button = "查询")
    @RequiresPermissions(value = {"admin:address:list"})
    @GetMapping("/list")
    public Object addressList(@RequestParam(defaultValue = "1") Integer page,
                              @RequestParam(defaultValue = "20") Integer limit,
                              @RequestParam(defaultValue = "add_time") String sort,
                              @RequestParam(defaultValue = "desc") String order){

        IPage<DtsAddress> iPage = dtsAddressService.selectPage(page,limit,sort,order);
        long total = iPage.getTotal();
        List<DtsAddress> records = iPage.getRecords();

        Map map = new HashMap();
        map.put("total",total);
        map.put("items", records);
        return ResponseUtil.ok(map);
    }

}
